Create Actors
Overview
Code
int global_seed = chi("global_seed");
// Time
float time_offset = chf("time_offset");
if( chs("time_offset_scale_style") == "attr" ){
if( chs("time_offset_scale_attr") != "" ){
time_offset *= f@offset_scale_attr;
}
}
else if( chs("time_offset_scale_style") == "rand11" ){
int rand_seed = chi("time_offset_scale_seed");
float rand = fit01(random(global_seed + rand_seed + i@ptnum + 1234567890), -1, 1);
time_offset *= rand;
}
else if( chs("time_offset_scale_style") == "rand01" ){
int rand_seed = chi("time_offset_scale_seed");
float rand = float(random(global_seed + rand_seed + i@ptnum + 1234567890));
time_offset *= rand;
}
float time = ch("time") + time_offset;
// Duration
float duration = chf("duration");
if( chs("duration_scale_style") == "attr" ){
if( chs("duration_scale_attr") != "" ){
duration *= f@duration_scale_attr;
}
}
else if( chs("duration_scale_style") == "rand01" ){
int rand_seed = chi("duration_scale_seed");
float rand = random(global_seed + rand_seed + i@ptnum + 2345678901);
duration *= rand;
}
float speed = 1/duration;
// Actor
int actor_id = i@ptnum; // Actor ID
int actor_seed = random_ihash(actor_id + global_seed); // Random Seed per actor
float actor_time = time/duration; // Relative lifetime within actor life, 0 to 1
float actor_age = time;
// Scene
int scene_index = int(floor(actor_time)); // Which scene number is being acted out
int scene_seed = random_ihash(scene_index + actor_seed); // Random Seed per Scene
float scene_time = frac(actor_time); // Relative scene time, 0 to 1
float scene_start_time = scene_index*duration - time_offset; // Absolute start time of actor
float scene_age = scene_time*duration; // Absolute time that the scene has been playing for
float scene_duration = duration; // Amount of time the scene will play out for
// Troupe
int troupe_id = floor(random(actor_seed + chi("troupe_seed"))*chi("troupe_count")); // Which troupe is the actor in
int troupe_seed = random_ihash(troupe_id+1000); // Random Seed per troupe
/////// Output Actor Attributes
if( chi("do_output_actorid") ){ // Actor ID
setpointattrib(0, chs("output_attr_actorid"), @ptnum, actor_id, "set"); }
if( chi("do_output_actorseed") ){ // Actor Seed
setpointattrib(0, chs("output_attr_actorseed"), @ptnum, actor_seed, "set"); }
if( chi("do_output_actortime") ){ // Actor Time
setpointattrib(0, chs("output_attr_actortime"), @ptnum, actor_time, "set"); }
if( chi("do_output_actorage") ){ // Actor Age
setpointattrib(0, chs("output_attr_actorage"), @ptnum, actor_age, "set"); }
/////// Output Scene Attributes
if( chi("do_output_sceneindex") ){ // Scene Index
setpointattrib(0, chs("output_attr_sceneindex"), @ptnum, scene_index, "set"); }
if( chi("do_output_sceneseed") ){ // Scene Seed
setpointattrib(0, chs("output_attr_sceneseed"), @ptnum, scene_seed, "set"); }
if( chi("do_output_scenestarttime") ){ // Scene Start Time
setpointattrib(0, chs("output_attr_scenestarttime"), @ptnum, scene_start_time, "set"); }
if( chi("do_output_scenetime") ){ // Scene Time
setpointattrib(0, chs("output_attr_scenetime"), @ptnum, scene_time, "set"); }
if( chi("do_output_sceneage") ){ // Scene Age
setpointattrib(0, chs("output_attr_sceneage"), @ptnum, scene_age, "set"); }
if( chi("do_output_sceneduration") ){ // Scene Life
setpointattrib(0, chs("output_attr_sceneduration"), @ptnum, scene_duration, "set"); }
/////// Output Troupe Attributes
if( chi("do_output_troupe_index") ){ // Troupe ID
setpointattrib(0, chs("output_attr_troupeid"), @ptnum, troupe_id, "set"); }
if( chi("do_output_troupe_seed") ){ // Troupe Seed
setpointattrib(0, chs("output_attr_troupeseed"), @ptnum, troupe_seed, "set"); }